import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({

  state: {
    SYSTEMPAGENAV: []
  },

  getters: {
    getSystemNav({SYSTEMPAGENAV}) {
      return SYSTEMPAGENAV
    },
    getKeepAliveComp({SYSTEMPAGENAV}) {
      return SYSTEMPAGENAV.map(pageNav => pageNav.name)
    }
  },

  mutations: {
    appendPageNav({SYSTEMPAGENAV}, payload) {
      let {name} = payload;
      let index = SYSTEMPAGENAV.findIndex(pageNav => pageNav.name === name);
      if (index <= -1) {
        SYSTEMPAGENAV.push(payload);
      }
    },

    deleteNav({SYSTEMPAGENAV}, payload) {
      console.log(payload)
      let {name} = payload;
      let index = SYSTEMPAGENAV.findIndex(pageNav => pageNav.name === name);
      if (index > -1) {
        SYSTEMPAGENAV.splice(index, 1);
      }
    }
  },


  actions: {

  }
})
